package top.lyc829.mymusic.model.repository

import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import top.lyc829.mymusic.model.http.AppException
import top.lyc829.mymusic.model.http.MyNetwork
import top.lyc829.mymusic.util.Const

/**
 * @Author lyc
 * @create 2021-09-02 10:54
 */
class CommentRepository(private val network : MyNetwork) {

    suspend fun getPlayListComments(id: Long, limit: Int = 20, offset: Int = 0) = withContext(
        Dispatchers.IO) {
        val result = network.getPlayListComments(id, limit, offset)
        if (Const.SUCCESS != result.code) {
            throw AppException(result.code, "获取歌单评论失败")
        }
        result
    }


    companion object {
        private var instance: CommentRepository? = null
        fun getInstance(network: MyNetwork): CommentRepository {
            if (instance == null) {
                synchronized(SongRepository::class.java) {
                    if (instance == null) {
                        instance = CommentRepository(network)
                    }
                }
            }
            return instance!!
        }

        const val TAG = "SongRepository"
    }
}